package gov.pbc.nn.kjgl.item.template.handler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.stereotype.Component;

import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.service.IDeptService;
import com.bstek.uflo.env.Context;
import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.process.handler.AssignmentHandler;
import com.bstek.uflo.process.node.TaskNode;

import gov.pbc.nn.core.bdf.entity.Dept;
import gov.pbc.nn.core.utils.SecurityUtils;
import gov.pbc.nn.kjgl.Constants;

/**
 * 获取申请部门部门综合员
 * 
 * @author Administrator
 * 
 */
@Component(ApplyZhyAssignmentHandler.BEAN_ID)
public class ApplyZhyAssignmentHandler implements AssignmentHandler {

	public static final String BEAN_ID = "gov.pbc.nn.kjgl.item.template.handler.ApplyZhyAssignmentHandler";

	@Override
	public Collection<String> handle(TaskNode arg0, ProcessInstance arg1, Context arg2) {
		Collection<String> users = new ArrayList<String>();
		String username = arg1.getPromoter();
		IDeptService ds = ContextHolder.getBean(IDeptService.BEAN_ID);
		String deptId = ((Dept) ds.loadUserDepts(username).get(0)).getCDept().getId();

		List<IUser> uList = SecurityUtils.getUserByRoleForDeptWithChildren(deptId, Constants.ROLE_ZHY);
		for (IUser u : uList) {
			users.add(u.getUsername());
		}
		return users;
	}

}
